/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.jmx.book;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

/**
 *
 * @author Administrator
 */
public class RMIClientFactory {

    public static MBeanServerConnection getClient() {
        /**
         * 这块代码就不要了 RmiConnectorClient client = new RmiConnectorClient();
         *
         * RmiConnectorAddress address = new RmiConnectorAddress();
         *
         * address.setPort(2099);
         *
         * System.out.println("/t/tTYPE/t= " + address.getConnectorType());
         *
         * System.out.println("/t/tPORT/t= " + address.getPort());
         *
         * System.out.println("/t/tHOST/t= " + address.getHost());
         *
         * System.out.println("/t/tSERVER/t= " + address.getName());
        *
         */
        //这是加进来的代码 
        MBeanServerConnection mbsc = null;
        try {
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:2099/server");  //JMX连接子服务端的地址 
            JMXConnector jmxc = JMXConnectorFactory.connect(url, null); //创建到服务端的连接 
            mbsc = jmxc.getMBeanServerConnection();
            //获得代表远程MBean server的一个MBeanServerConnection 对象 //client.connect( address ); 
        }
        catch (Exception e) {
            ExceptionUtil.printException(e);
        }

        return mbsc;
    }
}
